package com.qyer.search.model.aggregation;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * Created by tangzheng on 16/7/17.
 */
public class SetOutPlace implements Comparable<SetOutPlace>{

  @JsonProperty
  private String name;
  @JsonProperty
  private String id;
  @JsonProperty
  private int size;

  public SetOutPlace(String name, String id) {
    this.name = name;
    this.id = id;
  }

  public SetOutPlace(String name, String id, int size) {
    this.name = name;
    this.id = id;
    this.size = size;
  }

  public int getSize() {
    return size;
  }

  public void setSize(int size) {
    this.size = size;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getId() {
    return id;
  }

  public void setId(String id) {
    this.id = id;
  }

  @Override public boolean equals(Object o) {
    if (this == o)
      return true;
    if (o == null || getClass() != o.getClass())
      return false;

    SetOutPlace that = (SetOutPlace) o;

    if (!name.equals(that.name))
      return false;
    return id.equals(that.id);

  }

  @Override public String toString() {
    return "SetOutPlace{" +
      "name='" + name + '\'' +
      ", id='" + id + '\'' +
      ", size=" + size +
      '}';
  }

  @Override public int hashCode() {
    int result = name.hashCode();
    result = 31 * result + id.hashCode();
    return result;
  }

  @Override public int compareTo(SetOutPlace setOutPlace) {
    return (setOutPlace.getSize() - this.size);
  }

  public void add(SetOutPlace setOutPlace){
    if(this.name.equals(setOutPlace.getName())){
      this.size += setOutPlace.getSize();
    }
  }
}
